﻿using System.Collections.Generic;
using System.Linq;
namespace Library.WebControls.SimpleGridView {

	public class FilterDataCollection : List<FilterData> {
		private readonly SpGridView _grid;
		internal FilterDataCollection(SpGridView gridView) {
			_grid = gridView;
		}
		public FilterData Find(int visibleColumnIndex) {
			return this.FirstOrDefault(c => c.ColumnIndex == visibleColumnIndex);
		}

		public FilterData Find(string columnName) {
			for (var i = 0; i < _grid.VisibleColumns.Count; i++) {
				var col = _grid.VisibleColumns[i];
				if (col.Name == columnName) {
					return Find(i);
				}
			}

			return null;
		}

		public string FindValue(int visibleConlumnIndex) {
			var data = Find(visibleConlumnIndex);
			if (data == null) return null;
			return data.Value;
		}
		public string FindValue(string columnName) {
			var data = Find(columnName);
			if (data == null) return null;
			return data.Value;
		}
	}
}
